{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu001': 'hl', 'stu002': 'silver', 'stu003': 'baek'}\n"
     ]
    }
   ],
   "source": [
    "info = {\n",
    "    \"stu001\":\"hl\",\n",
    "    \"stu002\":\"silver\",\n",
    "    \"stu003\":\"baek\"\n",
    "}\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu001': 'hl', 'stu002': 'silver', 'stu1803': 'baek'}\n"
     ]
    }
   ],
   "source": [
    "info2 = dict(stu001=\"hl\",stu002=\"silver\",stu1803=\"baek\")\n",
    "print(info2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu001': 'hl', 'stu002': 'silver', 'stu003': 'baek'}\n"
     ]
    }
   ],
   "source": [
    "info3 = {}\n",
    "info3[\"stu001\"]=\"hl\"\n",
    "info3[\"stu002\"]=\"silver\"\n",
    "info3[\"stu003\"]=\"baek\"\n",
    "print(info3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu001': 'hl', 'stu002': 'silver', 'stu003': 'baek', 'stu004': 'bbh'}\n"
     ]
    }
   ],
   "source": [
    "info [\"stu004\"] = \"bbh\"\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu001': 'hl', 'stu002': 'silver', 'stu003': 'baek', 'stu004': 'web'}\n"
     ]
    }
   ],
   "source": [
    "info [\"stu004\"] = \"web\"\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu001': 'hl', 'stu002': 'silver', 'stu003': 'baek'}\n"
     ]
    }
   ],
   "source": [
    "info.pop(\"stu004\")\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu002': 'silver', 'stu003': 'baek'}\n"
     ]
    }
   ],
   "source": [
    "del info[\"stu001\"]\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu002': 'silver', 'stu003': 'baek'}\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu002': 'silver', 'stu003': 'baek', 'stu001': 'hl'}\n"
     ]
    }
   ],
   "source": [
    "info [\"stu001\"] = \"hl\"\n",
    "info [\"stu003\"] = \"baek\"\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu002': 'silver', 'stu003': 'baek'}\n"
     ]
    }
   ],
   "source": [
    "info.popitem()\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu001': 'hl', 'stu002': 'silver', 'stu003': 'baek'}\n"
     ]
    }
   ],
   "source": [
    "info = {\n",
    "    \"stu001\":\"hl\",\n",
    "    \"stu002\":\"silver\",\n",
    "    \"stu003\":\"baek\"\n",
    "}\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(\"stu002\" in info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "silver\n"
     ]
    }
   ],
   "source": [
    "print(info.get(\"stu002\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "silver\n"
     ]
    }
   ],
   "source": [
    "print(info[\"stu002\"]) #如果一个key不存在，就报错，get不会，不存在只返回None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(info.get(\"stu005\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'stu005'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-16-325218027f33>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minfo\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"stu005\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m: 'stu005'"
     ]
    }
   ],
   "source": [
    "print(info[\"stu005\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
